package services

import config._
import dao.GenomeDao
import javax.inject.{Inject, Singleton}
import org.apache.commons.io.FileUtils
import utils.TableUtils

import scala.collection.mutable
import scala.concurrent.ExecutionContext
import scala.jdk.CollectionConverters._

@Singleton
class OnStart @Inject()(genomeDao: GenomeDao)(implicit exec: ExecutionContext) extends MyFile with MyRow with MyAwait with MyJson {

  TableUtils.genome = genomeDao.getAllGenome.toAwait.groupBy(_.species).map { x =>
    x._1 -> x._2.sortBy(_.id).map(_.getMapByT())
  }


/*

  //blast Gene ID 和 Chr

  TableUtils.genome.foreach { x =>
    val geneid = x._2.map(_ ("geneid")).distinct
    val chr = x._2.map(_ ("chr")).distinct
    FileUtils.writeLines(s"I:/hordeum_db/blastData/${x._1}_geneid.txt".toFile, geneid.asJava)
    FileUtils.writeLines(s"I:/hordeum_db/blastData/${x._1}_chr.txt".toFile, chr.asJava)
  }
*/

  TableUtils.goMap = s"${Global.path}/configData/GOSDes.txt".readLines.map(_.split("\t")).map(x => x.head -> x.last).toMap

  TableUtils.chr = TableUtils.genome.map { x => x._1 -> x._2.map(_ ("chr")).distinct }


}
